<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ include file="/include/header.jsp"%>
<title>增加运价预警设置</title>

<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/show.js"></script>
<script	src="<%=request.getContextPath()%>/fare/lib/jquery/jquery.form.js"	type="text/javascript"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<link href="<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/fare/js/cityquery/citylist.js" type="text/javascript"></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/fdc.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath() %>/jsFile/wait/js/wait.js"></script>	
<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet">
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />
<base target="_self" />
</head>
<script >
function saveConfig(){
	//让原本隐藏起来的div显示出来
	//document.getElementById("save").style.display="block";
	 var flightFrom = $("#depCity").val(); 
	 var flightTo = $("#arrCity").val(); 
	if(flightFrom=="" || flightTo =="" || flightFrom=="<s:i18n name='forms'><s:text name='forms.cnOrPingYing'></s:text></s:i18n>" ||
			flightTo =="<s:i18n name='forms'><s:text name='forms.cnOrPingYing'></s:text></s:i18n>"){
		alert("<s:i18n name='forms'><s:text name='forms.chooseRoutes'></s:text></s:i18n>");
		return;
	}
	
	
	if(flightFrom==flightTo){
		alert("<s:i18n name='forms'><s:text name='forms.sameCity'></s:text></s:i18n>");
		return ;
	}
	
	if($("#flightNo").val()==''){
		alert("<s:i18n name='forms'><s:text name='forms.notFlight'></s:text></s:i18n>") ;
		return ;
	}
	if($("#flightDate").val()==''){
		alert("<s:i18n name='forms'><s:text name='forms.notFlightDate'></s:text></s:i18n>") ;
		return ;
	}
	/* var effectiveFrom = $("#_effectiveFrom").val();
	var effectiveTo   = $("#_effectiveTo").val();
	var s_date = new Date(effectiveFrom.replace(/-/g,"/"));
    var e_date = new Date(effectiveTo.replace(/-/g,"/")); */
    var alertWay = $("#_alertWay").val(); 
   
	/*  $.post('freightPriceAnalyseAlertConfigAction!saveCabinChangeAlertConfig.action',
				$("#formSave").serialize(),
				function(data){
			if(data && data=="succes"){
				alert('保存成功');
				FDCWait.hide();
				window.returnValue = "ok";
				window.close();
			}else{
				
				alert('保存失败!\n原因：'+data);
			}
	},'text'); */
	 $("#formSave").ajaxSubmit({
		   url:"freightPriceAnalyseAlertConfigAction!saveCabinChangeAlertConfig.action",
	    	type:"POST",
	    	async:false,
	    	cache : false, 
	    	 beforeSend:function(){	 FDCWait.show(); },
	    	success:function(data){
	    		closeCheckedWindow();
	    	},
	    	 error:function(){
	    		 alert("<s:i18n name='forms'><s:text name='forms.failure'></s:text></s:i18n>");
	    	 },
	    	 complete:function(){ 
 		    	FDCWait.hide();
 		    }
	    });
}	
function closeCheckedWindow(){
	alert("<s:i18n name='forms'><s:text name='forms.success'></s:text></s:i18n>");
	
	var ppWin = window.parent.dialogArguments.pWin;//父窗口
	ppWin.showDataAgain();
	window.parent.close();
}

function resetForm(){
	
	/* $("#_effectiveFrom").val("");
	$("#_effectiveTo").val("");
	
	$("#_flightFrom").val("");
	$("#_flightTo").val("");
	
	$("#_triggerCondition").val('');
	$("#_futureDays").val(''); */
	
}

var i=1;
function loadFlightNo(){
	var fromCity = $("#depCity").val();
	var toCity = $("#arrCity").val();
	var fromCityCode = $("#depCityCode").val();
	var toCityCode = $("#arrCityCode").val();
	//获得所选择的航空公司
	var carrier=$("input[name='companyCode']:checked").val(); 
	if(carrier == undefined){
		alert("<s:i18n name='forms'><s:text name='forms.chooseAirlines'></s:text></s:i18n>");
		return;
	}
	    		$.ajax({
	                  url : 'commonAction!outCityFlightNo.action',
	                  data : {'fromCity':fromCity,'toCity':toCity,'fromCityCode':fromCityCode,'toCityCode':toCityCode,'carrier':carrier},
	                  type : "POST",
	                  dateType:'json',
	                  beforeSend : function(XMLHttpRequest) {// 提交之前的处理代码放在此处,可空着
	                                    
	                  },
	                  success : function(data) {
	                	  $("#flightNo1").empty();
	                	  //document.getElementById("flightNo1").innerHTML="";
		                	  if(data==""||data==null){
		                		 $("#flightNo1").html("<option value=''>--<s:i18n name='forms'><s:text name='forms.select'></s:text></s:i18n>--</option>");
		                		  return ;
		                	  }
		                	 $("#flightNo1").html("<option value=''>--<s:i18n name='forms'><s:text name='forms.select'></s:text></s:i18n>--</option>");
	                	  var unitys_str=data.split("#");
	                	 	
	                	  for(var i=0;i<unitys_str.length;i++){
	                		  var s_unity=unitys_str[i].split("=")[1];
	                		  var flightNo = unitys_str[i].split("=")[0];
	                		  if((s_unity!="" && s_unity!=null && s_unity!= "undefined") &&  flightNo != "channelId"  ){
	                			  var opt=document.createElement("OPTION");
	                			  document.getElementById("flightNo1").options.add(opt);
	                			    opt.value=s_unity;
	                			    opt.text=s_unity;
	                		   }
	                	  }
	                	  document.getElementById("flightNo1").options[0].selected=true;
	                  },
	                  error : function(data) {
	                        alert('<s:i18n name="forms"><s:text name="forms.timeout"></s:text></s:i18n>');
	                  }
	            });
		
	
	i++;
}
function setTimeFunction(){
	 var objS = document.getElementById("flightNo"); 
    var grade = objS.options[objS.selectedIndex].grade;
    $("#flightTime").html(grade);
    if($("#flightNo").val()==""||$("#flightNo").val()==null) {
		 $("#flightTime").html("");
		 $("#Times").attr("value","");
	 }else{
    $("#Times").attr("value",grade);
		 
	 }
    if($("#flightNo").val()!=''){
   	 $("#time_select").hide('slow');
    }else{
   	 $("#time_select").show('slow');
    }
}

$(function(){
	 $(".chk").attr("checked",true);
	 
});


function getBack(){
	//让原本隐藏起来的div显示出来
	document.getElementById("save").style.display="none";
}

$(function(){
	var now = new Date(); //或全今天的日期-显示为日期和时间
	var now = new Date(); //或全今天的日期-显示为日期和时间
	now.setTime(now.getTime()+24*60*60*1000);
	var dateValue=now.getFullYear() + "-"+ (now.getMonth()+1)+"-"+(now.getDate()); //获取年月日

	/* $("#_effectiveFrom").val(dateValue);
	$("#_effectiveTo").val(dateValue); */
	
	//$('#flightFrom').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList,changeDoFusion: changeEvent});
	//$('#depCity').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList,changeDoFusion: changeEvent});
	$('#depCity').querycity({
				'data' : citysFlight,
				'tabs' : labelFromcity,changeDoFusion: changeEvent
			});
			$('#arrCity').querycity({
				'data' : citysFlight,
				'tabs' : labelFromcity,changeDoFusion: changeEvent
			});
	var flag = '${isUpdate}';
	if(flag=='yes'){
		var fromCity = '${vo.fromCityName}';
		var toCity = '${vo.toCityName}';
		findExistCompanyByCrawlLine(fromcity,tocity,fromCityCode,toCityCode);	
	}

	
	
/* 	$('#_flightFrom').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	$('#_flightTo').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	
	$('#flightFrom0').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
	$('#flightTo0').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList}); */
	
	
	
	/* $("#_flightFrom").css({
		"color":"black"
	});
	$("#_flightTo").css({
		"color":"black"
	}); */
});
function closeWindow(){
	if(window.confirm("<s:i18n name='forms'><s:text name='forms.closeCurrentWindow'></s:text></s:i18n>")){
		window.open('','_self','');
		window.close();
	}
}
function changeEvent(){
	 var tocity = $("#depCity").val();
	 var fromcity = $("#arrCity").val();
	 var fromCityCode = $("#depCityCode").val();
	 var toCityCode = $("#arrCityCode").val();
	 if((fromcity =='' && tocity !='')||(tocity=='<s:i18n name="forms"><s:text name="forms.cnOrPingYing"></s:text></s:i18n>'&&
			 fromcity=='<s:i18n name="forms"><s:text name="forms.cnOrPingYing"></s:text></s:i18n>')){
		 alert("<s:i18n name='forms'><s:text name='forms.chooseRoutes'></s:text></s:i18n>");
		 $("#fromCity").focus();
		 return false;
	 }else if(fromcity == tocity){
		 alert("<s:i18n name='forms'><s:text name='forms.sameCity'></s:text></s:i18n>");
		 $("#fromCity").focus();
		 return false;
	 }else if((fromcity !='' && tocity== '')||fromcity !='' && tocity== '<s:i18n name="forms"><s:text name="forms.cnOrPingYing"></s:text></s:i18n>'){
		 return false;
	 }else{
		 findExistCompanyByCrawlLine(fromcity,tocity,fromCityCode,toCityCode);
		 
	 }

	
}
function resetFlightNo(){
	$("select").each(function(i,n){
		 $(this).find("option").eq(0).attr("selected",'selected');
		});
}


function  findExistCompanyByCrawlLine(fromcity,tocity,fromCityCode,toCityCode){
	$.post("commonAction!findExistCompanyByCrawlLine.action", 
			 { "fromCity":fromcity,"toCity": tocity,"fromCityCode":fromCityCode,"toCityCode":toCityCode},
			   function(data){
				 $("#addCompanyTd").empty();
				 var jsonarray = data;
				 for(var i=0;i<jsonarray.length;i++){
					 	 
					 $("#addCompanyTd").append("<input type='radio' name='companyCode' onClick='loadFlightNo()' value='"+jsonarray[i].hbaseKey+"'/>"+jsonarray[i].shortName+" ");			 
					
				 	 
				 }
				
		   }, "json");
	
	
}
 // 

//离开页面事件
$(window).unload(function (){
	if(window._save==true){
		var parentWindow = window.dialogArguments;//父窗口
		parentWindow.location.href = parentWindow.location.href
	}
//window.opener.location.href = window.opener.location.href;
});
</script>
<body>
	<!-- 增加  -->
	<div id="save">
		<form id="formSave"   method="post"  target="_parent"  autocomplete="off">
			<input type="hidden" id="id" name="id" value="${id}"/>
			<input type="hidden" id="isUpdate" name="isUpdate" value="${isUpdate}"/>
			<TABLE cellSpacing=1 cellPadding=3 width="100%" border=0 class="form_table">
					<TR >
						<TD class="left" colspan="10" ><s:i18n name='forms'><s:text name='forms.cabinAlert'></s:text></s:i18n>
						<s:i18n name='forms'><s:text name='forms.setting'></s:text></s:i18n></TD>
					</TR>
					<TR >
						<TD width="100" height="100" style="text-align: left" class="left">
							<s:i18n name="forms"><s:text name="forms.explanation"></s:text></s:i18n>：</TD>
						<TD colspan="3">1、<s:i18n name="forms"><s:text name="forms.redAsterisk"></s:text></s:i18n>:<br/>
							<!-- 2、用户在设置运价预警规则后，当运价差额比例符合指定触发条件时，系统自动发消息(邮件/短信)给制定该规则的用户； --><br/>
							<!-- 3、同一航空公司下相同航线有且只有一条航线预警配置。 --><br/>
							<!-- 4、用户预警方式中，目前只支持邮件提醒。 --><br/>
						</TD>
					</TR>
			    <TR >
				    <TD width="100" class="left" style="text-align:left"><s:i18n name='forms'><s:text name='forms.trip'></s:text></s:i18n>：
				    <font color="red">&nbsp;&nbsp;&nbsp;&nbsp;*</font>
				    </TD>
				    <TD colspan="3" >
								 
 					<c:if test="${language=='en_US'}">
				    		<jsp:include page="/inc/flightSelect_en_Us.jsp">
							<jsp:param value="${fromCity}" name="fromCity"/>
							<jsp:param value="${fromCityCode}" name="fromCityCode"/>
							<jsp:param value="${toCity}" name="toCity"/>
							<jsp:param value="${toCityCode}" name="toCityCode"/>
							</jsp:include>
				    </c:if>
				    <c:if test="${language=='zh_CN' or language=='other'}">
				   			 <jsp:include page="/inc/flightSelect.jsp">
							<jsp:param value="${fromCity}" name="fromCity"/>
							<jsp:param value="${fromCityCode}" name="fromCityCode"/>
							<jsp:param value="${toCity}" name="toCity"/>
							<jsp:param value="${toCityCode}" name="toCityCode"/>
							</jsp:include>
				    </c:if> 
						
				     
				    </TD>
			  	</TR>
			  	
			  <TR >
				  	<TD width="100" height="26" class="left" style="text-align:left"><s:i18n name='forms'><s:text name='forms.airlines'></s:text></s:i18n>：
				  	<span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;*</span>
				    </TD>
				     <TD id="addCompanyTd" colspan="3">
				    
				    	<!-- <input type="radio" checked="checked" name="CompanyCode" value="20006"/>国航
				    	<input type="radio" name="CompanyCode" value="20005"/>南航
				    	<input type="radio" name="CompanyCode" value="20001"/>东航
				    	<input type="radio" name="CompanyCode" value="20000"/>深航
				    	<input type="radio" name="CompanyCode" value="20004"/>海航 -->
				    </TD>
				   <!--  <TD class="left">
				    	<input type="radio" name="CompanyCode" value="20006"/>国航
				    	<input type="radio" name="CompanyCode" value="20005"/>南航
				    	<input type="radio" name="CompanyCode" value="20001"/>东航
				    	<input type="radio" name="CompanyCode" value="20000"/>深航
				    	<input type="radio" name="CompanyCode" value="20004"/>海航
				    </TD> -->
				  
			  </TR>
			  
			   <TR >
				  	<TD width="100" height="26" class="left" style="text-align:left"><s:i18n name='forms'><s:text name='forms.flight'></s:text></s:i18n>：
				  <span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*</span>
				    </TD>
				    <TD >
				    	<select name="flightNo" id="flightNo1">
							<c:if test="${empty vo.flightNo }">
								<option value="">--<s:i18n name='forms'><s:text name='forms.select'></s:text></s:i18n>--</option>
							</c:if>
							<c:if test="${not empty vo.flightNo }">

								<option value="${vo.flightNo }">${vo.flightNo }</option>

							</c:if>
					    </select> 
					    	<span id="flightTime"></span>
					    	<font color="red"></font> 
					    		<input	id="Times" name="vo.flightTimes" type="hidden" value="flightDate" />
					</TD>
				
			  </TR>	
			  <TR >
				    <TD width="100" height="26" class="left" style="text-align:left" ><s:i18n name='forms'><s:text name='forms.flightDate'></s:text></s:i18n>：
				         <span style="color: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;*</span>
				    </TD>
				    <TD colspan="3">   
				      <input type="text" style="width:80px" id="flightDate" name="flightDate" value="${vo.flightDate }" 
				      	onClick="WdatePicker({skin:'whyGreen',lang:'<s:text name='forms.locale'/>',dateFmt:'yyyy-MM-dd',minDate:'%y-%M-{%d+1}'});" readonly="readonly">
					</TD>
			  </TR>
			
			  <TR align="center" >
			  		<TD colspan="4" class="left" style="text-align: center">
			  			 <input type="button" style="width:80px" id="btnSave" name="btnSave" 
			  			 	value="<s:i18n name='forms'><s:text name='forms.save'></s:text></s:i18n>" onclick="saveConfig()" />
			  			 <input type="reset" style="width:80px" id="btnReset" name="btnReset" 
			  			 	value="<s:i18n name='forms'><s:text name='forms.cleared'></s:text></s:i18n>"/>
			  			<!--  <input type="button" style="width:80px" id="btnClose" name="btnClose" value="关闭" onclick="closeWindow();" />  -->
			  		</TD>
			  </TR>
			</table>
		</form>
	</div>
</body>  
</html>